Rewrite xcsv_parse_style_buff() in a readable way
authorRobert Lipe <robertlipe@gpsbabel.org>
Tue, 31 Jul 2018 05:18:11 +0000 (00:18 -0500)
committerRobert Lipe <robertlipe@gpsbabel.org>
Tue, 31 Jul 2018 05:18:11 +0000 (00:18 -0500)
…might be more clever with a QStringRef, but this is hardly a
performance path.

xcsv.cc

diff --git a/xcsv.cc b/xcsv.cc
index a8905a9fe96947ff1547cf0e1fd7fd9e77316248..f617d72e1dbb1e4d4090760a2f6367b7155c58e8 100644 (file)
--- a/xcsv.cc
+++ b/xcsv.cc
@@ -419,22 +419,9 @@ xcsv_parse_style_line(QString line)
 static void
 xcsv_parse_style_buff(const char* sbuff)
 {
-  // FIXME: should not be a static buf.  Should not be a raw character
-  // buffer at all!
-  char ibuf[4096];
-
-  while (*sbuff) {
-    ibuf[0] = 0;
-    size_t i = 0;
-    char* ibufp;
-    for (ibufp = ibuf; *sbuff != '\n' && i++ < sizeof(ibuf);) {
-      *ibufp++ = *sbuff++;
-    }
-    while (*sbuff == '\n' || *sbuff == '\r') {
-      sbuff++;
-    }
-    *ibufp = 0;
-    xcsv_parse_style_line(ibuf);
+  QStringList lines = QString(sbuff).split('\n');
+  for (const auto& line : lines) {
+    xcsv_parse_style_line(line);
   }
 }